package com.netwit.common.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DataSourceContextHolder {
    private static final Logger logger = LoggerFactory.getLogger(DataSourceContextHolder.class);
    public  static final String DEFAULT_DS = "basic";
    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    public static void setDb(String dbName) {
        logger.debug("切换到 {} 数据源.", dbName);
        contextHolder.set(dbName);
    }

    public static String getDb() {
        return contextHolder.get();
    }

    public static void clear() {
        contextHolder.remove();
    }
}